package com.xiaoxu.intranetweb.mybatisplusSzappdb.controller.specialPrice;


import com.alibaba.fastjson.JSONObject;
import com.xiaoxu.intranetweb.mybatisplusSzappdb.business.specialPrice.SpecialPriceBu;
import com.xiaoxu.intranetweb.util.PermissionCheck;
import com.xiaoxu.intranetweb.util.SzResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xiaoxu
 * @since 2024-04-26
 */
@RestController
@RequestMapping("/specialPrice")
public class SpecialPriceController {
    @Autowired
    private SpecialPriceBu specialPriceBu;

    @GetMapping("/getAllSpecialPrices")
//EXECUTE_TYPE
    public SzResult getAllSpecialPrices(@RequestParam(value = "page", required = false)Integer page,
                                        @RequestParam(value = "pageSize", required = false)Integer pageSize,
                                        @RequestParam(value = "startTime", required = false)String startTime,
                                        @RequestParam(value = "endTime", required = false)String endTime,
                                        @RequestParam(value = "coId", required = false)String coId,
                                        @RequestParam(value = "pdtId", required = false)String  pdtId,
                                        @RequestParam(value = "priceTypeId", required = false)String priceTypeId,
                                        @RequestParam(value = "executeType", required = false) Integer executeType,
                                        HttpServletRequest request){
    String token = request.getHeader("Authorization");
    String plantId = request.getHeader("Plant-Id");
    return specialPriceBu.getAllSpecialPrices(page,pageSize,startTime,endTime,coId,pdtId,priceTypeId,executeType,token,plantId);
}
    @GetMapping("/getAllSpecialPriceType")
//EXECUTE_TYPE
    public SzResult getAllSpecialPriceType(@RequestParam(value = "typeName", required = false)String typeName,
                                        HttpServletRequest request){
        String plantId = request.getHeader("Plant-Id");
        return specialPriceBu.getAllSpecialPriceType(typeName,plantId);
    }
//    updateSpecialPriceType
    @PostMapping("/updateSpecialPriceTypeSort")
//EXECUTE_TYPE
    public SzResult updateSpecialPriceTypeSort(@RequestBody JSONObject jsonParam,
                                               HttpServletRequest request) throws Exception {
        String id = jsonParam.getString("id");
        Integer sort = jsonParam.getInteger("sort");
        String plantId = request.getHeader("Plant-Id");
        String token = request.getHeader("Authorization");
        return specialPriceBu.updateSpecialPriceTypeSort(id, sort,plantId,token);
    }
//    updateSpecialPriceTypeEnableFlag
    @PostMapping("/updateSpecialPriceTypeEnableFlag")
//EXECUTE_TYPE
    public SzResult updateSpecialPriceTypeEnableFlag(@RequestBody JSONObject jsonParam,
                                                     HttpServletRequest request) throws Exception {
        String id = jsonParam.getString("id");
        Integer enableFlag = jsonParam.getInteger("enableFlag");
        String plantId = request.getHeader("Plant-Id");
        String token = request.getHeader("Authorization");
        return specialPriceBu.updateSpecialPriceTypeEnableFlag(id, enableFlag,plantId,token);
    }
//    新增addSpecialPrice
    @PostMapping("/addSpecialPrice")
//EXECUTE_TYPE
    public SzResult addSpecialPrice(@RequestBody JSONObject jsonParam,
                                    HttpServletRequest request) {
        String id = jsonParam.getString("id");
        BigDecimal price = jsonParam.getBigDecimal("price");
        String priceTypeId = jsonParam.getString("priceTypeId");
        String priceType = jsonParam.getString("priceType");
        Integer executeType = jsonParam.getInteger("executeType");
        BigDecimal num = jsonParam.getBigDecimal("num");
        String pdtId = jsonParam.getString("pdtId");
        String coId = jsonParam.getString("coId");
        String startTime = jsonParam.getString("startTime");
        String endTime = jsonParam.getString("endTime");
        String priceDesc = jsonParam.getString("priceDesc");
        String token = request.getHeader("Authorization");
        String plantId = request.getHeader("Plant-Id");
        return specialPriceBu.addSpecialPrice(id,price, priceTypeId, priceType, executeType,num, pdtId, coId, startTime, endTime, priceDesc, token, plantId);
    }
    @PostMapping("/updateSpecialPriceDes")
//EXECUTE_TYPE
    public SzResult updateSpecialPriceDes(@RequestBody JSONObject jsonParam,
                                        HttpServletRequest request) {
        String id = jsonParam.getString("id");
        String priceDesc = jsonParam.getString("priceDesc");
        String token = request.getHeader("Authorization");
        String plantId = request.getHeader("Plant-Id");
        return specialPriceBu.updateSpecialPriceDes(id, priceDesc, token, plantId);
    }
//    修改定价数据
    @PostMapping("/updateSpecialPrice")
    @PermissionCheck("updateSpecialPrice")
//EXECUTE_TYPE
    public SzResult updateSpecialPrice(@RequestBody JSONObject jsonParam,
                                        HttpServletRequest request) {
        String id = jsonParam.getString("id");
        BigDecimal price = jsonParam.getBigDecimal("price");
        String priceTypeId = jsonParam.getString("priceTypeId");
        Integer executeType = jsonParam.getInteger("executeType");
        BigDecimal num = jsonParam.getBigDecimal("num");
        String pdtId = jsonParam.getString("pdtId");
        String coId = jsonParam.getString("coId");
        String startTime = jsonParam.getString("startTime");
        String endTime = jsonParam.getString("endTime");
        String priceDesc = jsonParam.getString("priceDesc");
        String token = request.getHeader("Authorization");
        String plantId = request.getHeader("Plant-Id");
        return specialPriceBu.updateSpecialPrice(id, price, priceTypeId, executeType, num, pdtId, coId, startTime, endTime, priceDesc, token, plantId);
    }
}
